<div class="companyTypes index">
<h2><?php __('CompanyTypes');?></h2>
<!-- Left Fat Section -->
<div class="widfats">
    <!-- Table Navigation -->
    <div class="tablenav">
        <div class="batchactions"></div>
        <?php echo $this->element('pager'); ?>
    </div>
    <!-- Table Content Area -->
    <table id="table_company_type" class="table fixed">
        <thead title="<?php __('Click a column to sort data table'); ?>">
            <tr>
                <th width="10%" class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox" /></th>
                <th width="15%"><?php echo $paginator->sort('id');?></th>
                <th width="20%"><?php echo $paginator->sort('name');?></th>
                <th width="30%"><?php echo $paginator->sort('company_count');?></th>
                <th width="25%" class="actions"><?php __('Actions');?></th>
            </tr>
        </thead>
        <tfoot title="<?php __('Click a column to sort data table'); ?>">
            <tr>
                <th class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox" /></th>
                <th><?php echo $paginator->sort('id');?></th>
                <th><?php echo $paginator->sort('name');?></th>
                <th><?php echo $paginator->sort('company_count');?></th>
                <th class="actions"><?php __('Actions');?></th>
            </tr>
        </tfoot>
        <tbody>
            <?php foreach ($companyTypes as $i=>$companyType):
                $class = $i++ % 2 == 0 ? ' class="altrow"' : ''; ?>
            <tr<?php echo $class;?>>
                <td class="checkbox"><input type="checkbox" class="checkbox" /></td>
                <td><?php echo $companyType['CompanyType']['id']; ?></td>
                <td><?php echo $companyType['CompanyType']['name']; ?></td>
                <td><?php echo $companyType['CompanyType']['company_count']; ?></td>
                <td class="actions">
                    <?php echo $html->link(__('View', true), array('action' => 'view', $companyType['CompanyType']['id'])); ?>
                    <?php if($user['group'] != 'student'): ?>
                        <?php echo $html->link(__('Edit', true), array('action' => 'edit', $companyType['CompanyType']['id'])); ?>
                        <?php echo $html->link(__('Delete', true), array('action' => 'delete', $companyType['CompanyType']['id'])); ?>
                    <?php endif; ?>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <!-- Company view section -->
    <div id="company_by_type"></div>
</div>
<!-- Sidebar Section -->
<div class="sidebar">
    <!-- CompanyType Add Form -->
    <div id="widget_add_company_type" class="widget">
        <div class="toggle">&nbsp;</div>
        <h3 class="handle"><span><?php __('Add CompanyType');?></span></h3>
        <div class="content">
            <div class="CompanyIndustries form">
            <!-- CompanyType Add Form -->
            <?php e($form->create('CompanyType', array('action'=>'add'))); ?>
                <fieldset>
                    <?php e($form->input('name', array('label'=>__('CompanyType', true), 'class' => 'text input', 'autocomplete'=>'off'))); ?>
                    <?php e($form->submit(__('Add CompanyType', true), array('class' =>'submit attention'))); ?>
                </fieldset>
            <?php e($form->end()); ?>
            </div>
        </div>
    </div>
    <!-- CompanyType Edit Form -->
    <div id="widget_edit_company_type" class="widget">
        <div class="toggle">&nbsp;</div>
        <h3 class="handle"><span><?php __('Edit CompanyType');?></span></h3>
        <div class="content">
            <p class="faq"><?php __('There are no CompanyType to edit now'); ?></p>
        </div>
    </div>
    <!-- Quick Actions -->
    <div id="widget_quick_actions" class="widget">
        <div class="toggle">&nbsp;</div>
        <h3 class="handle"><span><?php __('Quick Actions');?></span></h3>
        <div class="content">
            <div class="actions">
                <ul>
                    <li><?php echo $html->link(__('List Companies', true), array('controller' => 'companies', 'action' => 'index')); ?> </li>
                    <li><?php echo $html->link(__('New Company', true), array('controller' => 'companies', 'action' => 'add')); ?> </li>
                    <br class="clear"/>
                </ul>
            </div>
        </div>
    </div>
</div>
</div>
<script type="text/javascript">
jQuery(function(){
    // Validate CompanyTypeAddForm
    $.sme.data.company_type = false;
    $('#CompanyTypeAddForm').submit(function(){
        if(!$(this).valid()){ return false; }
        if(!$.sme.status.company_type){
            $.sme.notify('error', '该性质已经存在, 不能添加');
            return false;
        }
    }).validate({
        success: function(label){
            $.sme.cbk.ajaxCheck.apply({
                label: label,
                input: label.prev('input'),
                id: 'CompanyTypeName',
                model: 'CompanyType',
                control: 'company_type',
                fielden: 'name',
                fieldzh: '性质'
            });
        },
        rules: { 'data[CompanyType][name]': 'required' },
        messages: { 'data[CompanyType][name]': '性质称不能为空值' }
    });

    // Validate CompanyTypeEditForm
    $('#CompanyTypeEditForm').submit(function(){
        if(!$(this).valid()){ return false; }
        if(!$.sme.status.company_type){
            alert('该性质已经存在, 不能添加');
            return false;
        }
        var target = $('div#widget_edit_company_type div.content');
        $(this).ajaxSubmit({
            global: false,
            target: target,
            beforeSend: function(){
                target.append($.sme.option.span);
            }
        });
        return false;
    }).validate({
        success: function(label){
            $.sme.cbk.ajaxCheck.apply({
                label: label,
                input: label.prev('input'),
                id: 'CompanyTypeName',
                model: 'CompanyType',
                control: 'company_type',
                fielden: 'name',
                fieldzh: '性质'
            });
        },
        rules: { 'data[CompanyType][name]': 'required' },
        messages: { 'data[CompanyType][name]': '性质称不能为空值' }
    });

    // Bind CompanyLocation  Edit/View/Delete callbacks
    $('table#table_company_type td.actions a[href*=edit]')
        .data('ajax', 'div#widget_edit_company_type div.content')
        .click($.sme.cbk.ajaxView);
    $('table#table_company_type td.actions a[href*=view]')
        .data('ajax', 'div#company_by_type')
        .click($.sme.cbk.ajaxView);
    $('table#table_company_type td.actions a[href*=delete]')
        .click($.sme.cbk.ajaxDelete);

});

// Extend $.sme.cbk with some methods
$.extend($.sme.cbk, {});
</script>